home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / ncpfs / mars_dos.000 / mars_dos / netpc / teste.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-26  |  2.6 KB  |  96 lines

  1. int main()
  2. {
  3.    char *fn="F.$LN";
  4.    char *string="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz";
  5.    int  result;
  6.    struct stat stbuff;
  7.    long offset;
  8.    char buff[1024];
  9.    char readbuff[500];
  10.    int j;
  11.    int  fd=creatnew(fn, S_IREAD |S_IWRITE);
  12.    if (fd > -1) {
  13.      printf("Konnte Date erzeugen\n");
  14.      close(fd);
  15.    } else {
  16.      printf("Konnte Datei nicht erzeugen\n");
  17.    }
  18.    fd = open(fn, O_RDWR|O_CREAT|O_TRUNC|O_DENYNONE, 0666);
  19.    memset(buff, 0, sizeof(buff) );
  20.    strcpy(buff, string);
  21.    write(fd, buff, strlen(buff));
  22.    close(fd);
  23.    _chmod(fn, 1, _chmod(fn, 0) | 0x80 );
  24.    stat(fn, &stbuff);
  25.    printf("Filesize über stat =%ld\n", stbuff.st_size);
  26.    fd = open(fn, O_RDWR | O_BINARY |O_DENYNONE);
  27.  
  28.    offset = lseek(fd, 0L, SEEK_END);
  29.    printf("Filesize über lseek =%ld\n", offset);
  30.    write(fd, buff, strlen(buff));
  31.  
  32.    lseek(fd, 0L, SEEK_SET);
  33.    for (j=0; j < strlen(buff)*2; j++){
  34.      read(fd, readbuff, 1);
  35.      printf("BUFF = %c\n",  readbuff[0]);
  36.    }
  37.    lseek(fd, 1L, SEEK_SET);
  38.    for (j = 0; j < 20; j++){
  39.      write(fd, buff+j, 1);
  40.    }
  41.  
  42.    for (j=0; j <60; j++){
  43.      lseek(fd, (long) j, SEEK_SET);
  44.      read(fd, readbuff, 2);
  45.      printf("BUFF = %c, %c \n", readbuff[0], readbuff[1]);
  46.    }
  47.  
  48.    lseek(fd, 10L, SEEK_SET);
  49.    read(fd, buff, 1);
  50.    printf("BUFF[10] = %c\n", buff[0]);
  51.    result=lock(fd,  100L, 1L);
  52.    printf("lock result = %d\n", result);
  53.    result=unlock(fd,  100L, 1L);
  54.    printf("unlock result = %d\n", result);
  55.    close(fd);
  56.  
  57.    fd = open(fn, O_BINARY|O_RDWR|O_CREAT|O_TRUNC|O_DENYNONE, 0666);
  58.    if (fd > -1) {
  59.      int bufflen;
  60.      strcpy(buff, "d:..\\marlib\\c0l.obj+");
  61.      strcat(buff, "\r\n");
  62.      strcat(buff, "x");
  63.      strcat(buff, "\r\n");
  64.      strcat(buff, "x");
  65.      strcat(buff, "\r\n");
  66.      strcat(buff, "/c/x");
  67.      strcat(buff, "\r\n");
  68.      strcat(buff, "d:..\\marlib\\EMU.LIB+");
  69.      strcat(buff, "\r\n");
  70.      strcat(buff, "d:..\\marlib\\mathl.lib+");
  71.      strcat(buff, "\r\n");
  72.      strcat(buff, "d:..\\marlib\\cl.lib");
  73.      bufflen=strlen(buff);
  74.      printf("bufflen = %d, buff=%s\n", bufflen, buff);
  75.      write(fd, buff, bufflen);
  76.      close(fd);
  77.      fd = open(fn, O_TEXT|O_RDONLY);
  78.      if (fd > -1) {
  79.        char *p=readbuff;
  80.        int  anz = 0;
  81.        memset(readbuff, 0, sizeof(readbuff) );
  82.        while (read(fd, p, 1) == 1){
  83.          anz++;
  84.          p++;
  85.        }
  86.        printf("read = %d, buff=%s\n", anz, readbuff);
  87.        close(fd);
  88.      }
  89.    }
  90.   /*
  91.   result = detach(1);
  92.   printf("Detach result=0x%x", result);
  93.   */
  94.   return(0);
  95. }
  96.